package org.example.code.test2024.nine_mouth;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;

public class test0919 {
    public int firstUniqChar(String s) {
        Queue<int[]> q = new LinkedList<int[]>();
        Map<Character,Integer> map = new HashMap<Character,Integer>();
        for(int i = 0; i < s.length(); i++){
            char c = s.charAt(i);
            if(map.containsKey(c)){
                map.put(c,map.get(c)+1);
            }else{
                map.put(c,1);
            }
            q.offer(new int[]{c,i});
        }
        while(!q.isEmpty()){
            int[] arr = q.peek();
            char c = (char)arr[0];
            if(map.get(c)==1){
                return arr[1];
            }
            q.poll();
        }
        return -1;
    }



    public static void main(String[] args) {
        test0919 test = new test0919();
        System.out.println(test.firstUniqChar("leetcode"));
    }
}
